var params = $.urlGet();
var access_token = params.token
console.log(access_token)
//get数据
$.ajax({
    type: "post",
    url: `http://t.api.antfre.com/user/view-horseman?access_token=${access_token}`,
    data: "",
    dataType: "json",
    success: function (res) {
        console.log(res)
        var horesman = res.data.user.horseman_status
        console.log(horesman)
        if(horesman == 0){
            location.href = './login.html'
        }else if(horesman == 1 || horesman == 3){
            layer.msg(res.message)
        }else{
            horsemanRoute(res.data)
        }
    }
});
//页面渲染
function horsemanRoute(man){
    console.log(man.title)
     var title = man.title
     var data = man.list
     var html = ''
     console.log(man.list)
     $.each(data,function(index,item){
         console.log(item.name)
         html += `<div class="content" data-id="${item.id}" onclick="paveHandle(this)">
    <div class="pull-left">
      <div>
        ${item.name}
      </div>
      <div>
        ${item.address}
      </div>
    </div>
    <div class="pull-rigth">
     ${item.status_text}
    </div>
</div>`
        $('.container').html(html)
         $('.title').text(title)
     })
}
//点击跳转
function paveHandle(e){
    var name = e.children[0].children[0].innerText
    var id = e.getAttribute("data-id")
    $.ajax({
        type: "post",
        url: 'http://t.api.antfre.com/stock-bill/can-put',
        data: {
            access_token:access_token,
            id:id,
        },
        dataType: "json",
        success:function (res) {
            console.log(res)
            if(res.success){
                // window.location.href = './index.html?id='+id+'&token='+ access_token +'&name='+ name +''
            }else {
                layer.msg(res.message)
                window.location.href = './index.html?id='+id+'&token='+ access_token +'&name='+ name +''
            }
        }
    })
}
